﻿using ch03.binary.type;

namespace ch03.binary.wasm_reader
{
    public partial struct WasmReader
    {
        // table sec
        private TableType[] ReadTableSec()
        {
            var vec = new TableType[ReadVarU32()];
            for (var i = 0; i < vec.Length; i++)
            {
                vec[i] = ReadTableType();
            }

            return vec;
        }

        private TableType ReadTableType()
        {
            var tt = new TableType
            {
                ElemType = ReadByte(),
                Limits = ReadLimits(),
            };
            if (tt.ElemType != ConstData.FuncRef)
            {
                Panic.Run("invalid elemtype: {0:D}", tt.ElemType);
            }

            return tt;
        }
    }
}